home *** CD-ROM | disk | FTP | other *** search
- /*
- File: GraphicsState.c
-
- Contains: QuickDraw GX to PostScript conversion code.
- File contains primitive routines for setting
- things in the PostScript graphics state that
- aren't contained in specific files. (Colors
- and text styles for example are in their own files)
-
- Version: Technology: Quickdraw GX 1.1.x
-
- Copyright: © 1990-1997 by Apple Computer, Inc., all rights reserved.
- */
-
- #include "GXToPSBuildConfig.h"
- #include <GXGraphics.h>
- #include "GXGraphicsPriv.h"
- #include <GXEnvironment.h>
- #include "GXToPostScript.h"
- #include "IOUtilities.h"
- #include "RDUtil.h"
- #include "FontHandler.h"
- #include "PublicPostScriptIE.h"
- #include "private.h"
- #include "PSIEResources.h"
- #include "GXErrors.h"
- #include "ShapeUtilities.h"
-
- #ifdef resumeLabel
- #undef resumeLabel
- #endif
- #define resumeLabel(exception)
-
- /*******************************
-
- MappingPrimitive:
-
- Routine concatonates the mapping with the CTM
- in the current PostScript graphics state.
-
- mapCTM takes the 6 matrix components and the 3,3 component as a scaling.
-
- *********************************/
- OSErr MappingPrimitive(TIEGlobalsHdl hIEGlobals, gxMapping *theMapping)
- {
- OSErr status;
- TRDParams* pRDParams;
-
-
- pRDParams = (*hIEGlobals)->pRDParams;
-
- pRDParams->resIndex = kMapCTM;
-
- status = RDResPrintf(pRDParams, theMapping->map[0][0], theMapping->map[0][1],
- theMapping->map[1][0], theMapping->map[1][1],
- theMapping->map[2][0], theMapping->map[2][1],
- theMapping->map[2][2]
- );
- ncheck(status);
- return(status);
-
- }//MappingPrimitive
-
- //<FF>
- /**********************************
-
- DoGsave:
-
- Do a gsave (both in our private graphics state and on the printer)
- First time it is called, it initializes our root level graphics state.
-
- internalOnly: pass true if we only want to nest out internal state
- without actually outputting a "gsave" operator
-
- ************************************/
- OSErr _DoGsave(TIEGlobalsHdl hIEGlobals, Boolean internalOnly)
- {
- OSErr status;
- TIEGlobalsPtr pGlobals;
- TRDParams* pRDParams;
- gxTransform currTransform;
- gxInk currInk;
- gxTag currHalftoneTag;
- gxColorProfile currProfile;
- TGstate *pGstate;
-
- pGlobals = *hIEGlobals;
- require (pGlobals->gStateDepth < pGlobals->params.gsaveLimit, failed_TooManyGsaves);
-
- if (!internalOnly) {
-
- /** Output a gsave operator **/
-
- pRDParams = pGlobals->pRDParams; // grab the RD parameters while we're here.
-
- pRDParams->resIndex = kGsave; // Output the gsave operation.
- status = RDResPrintf(pRDParams);
- nrequire(status, failed_Gsave);
-
- pGlobals = *hIEGlobals; // Get it again, I/O could have moved it.
-
- }//end if
-
-
- /****
- gsave on our internal state:
- This means copy the current level into the next level
- and bump up our level index.
- Clone elements so that new level is an ownder of them.
- *****/
-
- BlockMove((Ptr)&(pGlobals->gStateNest[pGlobals->gStateDepth]),
- (Ptr)&(pGlobals->gStateNest[pGlobals->gStateDepth + 1]),
- sizeof(TGstate)
- );
-
- pGlobals->gStateDepth += 1;
-
- pGstate = &(pGlobals->gStateNest[pGlobals->gStateDepth]);
-
- pGstate->flags = eNoGstateFlags;
-
- // Clone the ink and profile and transform and halftone tag for the new level.
- currTransform = pGstate->theTransform;
- currInk = pGstate->theInk;
- currHalftoneTag = pGstate->halftoneTag;
- currProfile = pGstate->currProfile;
-
- GXCloneTransform(currTransform);
- GXCloneInk(currInk);
-
- if (currProfile != nil)
- GXCloneColorProfile(currProfile);
-
- if (currHalftoneTag != nil)
- GXCloneTag(currHalftoneTag);
-
- status = GXGetGraphicsError(nil);
-
-
- failed_Gsave:
-
-
- return(status);
-
-
- failed_TooManyGsaves:
-
- return(-9999);
-
- }//DoGsave
-
-
-
- //<FF>
- /**********************************
-
- DoGrestore:
-
- Do a grestore (both in our private graphics state and on the printer)
- This grestore will preserve the style.
-
- internalOnly: Boolean indicating do do grestore only on internal state
- (that is don't actually output a grestore command to the printer)
-
- ************************************/
- OSErr _DoGrestore(TIEGlobalsHdl hIEGlobals, Boolean internalOnly)
- {
- OSErr status = noErr;
- TIEGlobalsPtr pGlobals;
- TRDParams* pRDParams;
- TGstate *pGstate;
-
- pGlobals = *hIEGlobals;
- if (pGlobals->gStateDepth >= 0) { // Grestoring with no gsave just does nothing, just like PostScript®
-
- /*** If we are doing a grestore on the printer: ***/
- if (!internalOnly) {
-
- /**********
- If there is a save at this graphics state level,
- do a restore otherwise the grestore would have no effect
- because you can't grestore past a save level
- **********/
- if (pGlobals->gStateNest[pGlobals->gStateDepth].flags & eGstateDidSave) {
-
- pGlobals->gStateNest[pGlobals->gStateDepth].flags &= ~eGstateDidSave;
-
- status = RDFlushBuffer(pGlobals->rdMap); // font handler can do buffer data.
- nrequire(status, failed_FlushBuffer);
-
- if ((*hIEGlobals)->fhContext != nil) { // DL 7/19/97.
- status = FontHandlerBalanceSaveLevel((*hIEGlobals)->fhContext);
- nrequire(status, failed_BalanceSave);
- }//end if
-
- /** Because we did a restore, things in the persistent state may be wrong **/
-
- (*hIEGlobals)->ieStateFlags |= (eStyleOutOfDate + eFontOutOfDate);
-
- }//end if
-
-
- /*** Now output the grestore ***/
-
- pRDParams = (*hIEGlobals)->pRDParams; // grab the RD parameters.
- pRDParams->resIndex = kQD2Grestore; // Output the grestore operation.
- status = RDResPrintf(pRDParams);
- nrequire(status, failed_Grestore);
-
- }//end if
-
-
- /*****
- Do a gsave on our internal state. This means decrementing the level
- and disposing of items owned by the level we are restoring from
- *****/
-
- pGlobals = *hIEGlobals;
- pGstate = &(pGlobals->gStateNest[pGlobals->gStateDepth]);
-
- DisposeGstateItems(pGstate);
-
- // Decrement the current nesting level
-
- --((*hIEGlobals)->gStateDepth);
-
-
- }//end if
-
- failed_Grestore:
- failed_BalanceSave:
- failed_FlushBuffer:
-
- return(status);
-
- }//DoGrestore
-